﻿using System;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.Serialization;
using SchoolSystem.Data;
using System.Collections.Generic;

namespace SchoolSystem.Server.Models
{
    [DataContract(Name = "discipline")]
    public class DisciplineForStudentModel : DisciplineModel
    {
        [DataMember(Name = "teacher")]
        public TeacherModel Teacher { get; set; }

        [DataMember(Name = "grades")]
        public IEnumerable<GradeModel> Grades { get; set; }

        public static Expression<Func<Discipline, DisciplineForStudentModel>> FromDiscipline
        {
            get
            {
                return d => new DisciplineForStudentModel()
                {
                    Id = d.DisciplineId,
                    Name = d.Name,
                    Teacher = d.Teachers.Intersect(d.Class.Teachers).AsQueryable()
                    .Select(TeacherModel.FromTeacher).FirstOrDefault(),
                    Grades = d.Grades.AsQueryable().Select(GradeModel.FromGrade)
                };
            }
        }
    }
}